﻿using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using CID.Domain.Development;
using CID.Domain.Operations;
using CID.Execution.Support.Information;

namespace CID.Execution.Support.Scripting
{
    [DataContract]
    public class DeploymentScriptStep : ScriptStep
    {
        internal DeploymentScriptStep() : base() { }

        //TODO: remove
        public DeploymentScriptStep(IVersion version, IEnvironment targetEnvironment) 
            : base(version.DeploymentDefinition.DeploymentTemplate, version.DeploymentDefinition.GetDeploymentParamaterValues(targetEnvironment))
        {
            Version = new VersionInfo(version);
            Package = new PackageInfo(version.ActivePackage);
        }

        public DeploymentScriptStep(IVersion version, IEnvironment targetEnvironment, IEnumerable<IServer> targetServers)
            : base(version.DeploymentDefinition.DeploymentTemplate, version.DeploymentDefinition.GetDeploymentParamaterValues(targetEnvironment), targetServers)
        {
            Version = new VersionInfo(version);
            Package = new PackageInfo(version.ActivePackage);
        }

        [DataMember]
        public VersionInfo Version { get; set; }

        [DataMember]
        public PackageInfo Package { get; set; }

        public DeploymentScriptStep Clone()
        {
            return new DeploymentScriptStep() { Package = Package.Clone(), ParameterValues = ParameterValues.Select(x => x.Clone()).ToArray(), Template = Template.Clone(), Version = Version.Clone() };
        }
    }
}
